home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 649 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.2 KB  |  70 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Streams and eof()
  5. Date: 6 Mar 1996 18:41:51 GMT
  6. Organization: ?
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <9603061838.AA11984@lts.sel.alcatel.de>
  9. References: <199603010214.VAA16273@pleiades.cs.rpi.edu> <KANZE.96Mar4112305@gabi.gabi-soft.fr> <4hgap6$6o7@fu-berlin.de>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Content-Type: text
  12. In-Reply-To: axl@zedat.fu-berlin.de's message of 05 Mar 1996 09:40:45 PST
  13. Content-Length: 2268
  14. X-Lines: 45
  15. Originator: clamage@taumet
  16.  
  17. In article <4hgap6$6o7@fu-berlin.de> axl@zedat.fu-berlin.de (Axel
  18. Thimm) writes:
  19.  
  20. |> kanze@gabi-soft.fr (J. Kanze) wrote:
  21.  
  22. |> >You might want to try the function `peek'.  I tend to use this function
  23. |> >a lot.  Basically, this forces a look-ahead, which will set the eof if
  24. |> >there is nothing more there.
  25.  
  26. |> But I think that you can use this only with text streams, not with
  27. |> binary streams (You would not be able to tell a eof-char from an
  28. |> ordinary binary char).
  29.  
  30. The functions istream::peek() and istream::get() return an int, not a
  31. char.  Exactly what this int is supposed to contain when the read
  32. succeeds is not particularly clear from the draft, but I would suppose
  33. that the intent is for the results to be basically the same as that of
  34. fgetc in C: either the char read, cast to unsigned char, then to char,
  35. or EOF (which must be negative).
  36.  
  37. Thus, in implementations where sizeof( int ) > sizeof( unsigned char),
  38. you shouldn't have any problems.  In the rare case where sizeof( int )
  39. == sizeof( unsigned char ), this isn't the only problem: there will be
  40. unsigned char's whose value doesn't fit in an int, and the mapping of
  41. them to the int is implementation defined.  (An implementation could,
  42. for example, map them all to 0.)
  43.  
  44. Since this is comp.STD.c++, I should really talk about what the draft
  45. standard says.  In the draft standard, of course, there is no EOF,
  46. only a function `ios_traits::eof()'.  At present, all that is
  47. guaranteed is that this function returns ``an int_type value which
  48. represents the end-of-file.''  At present, there is nothing (except
  49. market pressure and common sense, neither of which have anything to do
  50. with the standard) to prevent an implementation from defining 'a' as
  51. eof.  A simple solution would be to require that this value not be
  52. representable in a ios_traits::char_type.  While this might be
  53. difficult for an implementation in which all integral types are the
  54. same size, I'd rather they had the difficulty than me.
  55.  
  56. --
  57. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  58. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  59. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  60.                 -- A la recherche d'une activitΘ dans une region francophone
  61.  
  62.  
  63.  
  64. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  65.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  66.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  67.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  68.   Comments? mailto:std-c++-request@ncar.ucar.edu
  69. ]
  70.